
package DAO;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import model.Role;
import util.DataUtil;

public class RoleDAO {

    public static List<Role> getRole() {
        List<Role> list = new ArrayList<Role>();
        String call = "{Call GET_ROLE}";
        try {
            CallableStatement cs = DataUtil.getConnection().prepareCall(call);
            ResultSet rs = cs.executeQuery();
            while (rs.next()) {
                Role rl = new Role();
                rl.setId(rs.getInt("RoleID"));
                rl.setName(rs.getString("RoleName"));
                list.add(rl);
            }
        } catch (SQLException ex) {
            list = null;
            ex.printStackTrace();
        }
        return list;
    }
}
